import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

// import store from '../store'
/* Layout */
import Layout from '@/layout'




/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */


export const constantRoutes = [
  //登录路由
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  //请求错误路由
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  //首页路由
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
]




export const studentRoutes = [
  //培养方案
  {
    path: '/train',
    redirect: '/train/course',
    component: Layout,
    name: 'Train',
    meta: { title: '培养方案', icon: 'train' },
    children: [
      {
        path: 'course',
        name: 'Course',
        component: () => import('@/views/train/course/index'),
        meta: { title: '理论课程', icon: 'theorycourse' }
      },
      {
        path: 'practice',
        name: 'Practice',
        component: () => import('@/views/train/practice/index'),
        meta: { title: '实践环节', icon: 'practice' }
      },

    ]
  },
  //选课
  {
    path: '/selectcourse',
    component: Layout,
    name: 'Selectcourse',
    redirect: '/selectcourse/positiveselect',
    name: 'Selectcourse',
    meta: { title: '网上选课', icon: 'selectcourse' },
    children: [
      {
        path: 'positiveselect',
        name: 'Positiveselect',
        component: () => import('@/views/selectcourse/positiveSelection'),
        meta: { title: '正选', icon: 'table' }
      },
      {
        path: 'positiveresult',
        name: 'Positiveesult',
        component: () => import('@/views/selectcourse/positiveResult'),
        meta: { title: '正选结果', icon: 'positiveresult' }
      }
    ]
  },
  //考试
  {
    path: '/exam',
    redirect: '/exam/examplan',
    component: Layout,
    name: 'Exam',
    meta: { title: '考试安排', icon: 'form' },
    children: [
      {
        path: 'examplan',
        name: 'Examplan',
        component: () => import('@/views/exam/examplan.vue'),
        meta: { title: '考试安排表', icon: 'examplan' }
      },
      {
        path: 'mendexam',
        name: 'Mendexam',
        component: () => import('@/views/exam/mendexam.vue'),
        meta: { title: '补考', icon: 'mendexam' }
      }
    ]
  },

  {
    path: '/teachingplan',
    redirect: '/teachingplan/teachingpalntable',
    component: Layout,
    name: 'Teachingplan',
    meta: {
      title: '教学安排',
      icon: 'teacherplan'
    },
    children: [
      {
        path: 'teachingpalntable',
        name: 'Teachingpalntable',
        component: () => import('@/views/teachingplan/TeachingPlanTable.vue'),
        meta: { title: '教学安排表', icon: 'teacherplantable' }
      },
      {
        path: 'mixorsuspend',
        name: 'Mixorsuspend',
        component: () => import('@/views/teachingplan/MixOrSuspend.vue'),
        meta: { title: '调/停课信息', icon: "mixorsuspend" }

      }
    ]

  },
]



export const adminRoutes = [
  //课程管理
  {
    path: '/coursemanagement',
    redirect: '/coursemanagement/updatesubject',
    component: Layout,
    name: 'Coursemanagement',

    children: [
      {
        path: 'updatesubject',
        name: "Updatesubject",
        component: () => import('@/views/coursemanagement/Coursemanagement.vue'),
        meta: {
          title: '课程管理',
          icon: 'course'
        },
      }
    ]
  },

  //学生管理
  {
    path: '/studentmanagement',
    redirect: '/studentmanagement/updatestudent',
    component: Layout,
    name: 'Studentmanagement',

    children: [
      {
        path: 'updatestudent',
        name: "Updatestudent",
        component: () => import('@/views/studentmanagement/Studentmanagement.vue'),
        meta: {
          title: '学生管理',
          icon: 'student'
        },
      }
    ]
  },
  //教师管理
  {
    path: '/teachermanagement',
    redirect: '/teachermanagement/updateacher',
    component: Layout,
    name: 'Teachermanagement',

    children: [
      {
        path: 'updateacher',
        name: "Updateacher",
        component: () => import('@/views/teachermanagement/Teachermanagement.vue'),
        meta: {
          title: '教师管理',
          icon: 'teacher'
        }
      }
    ]
  },

  //修改密码
  {
    path: '/changepassword',
    redirect: '/changepassword/updatepassword',
    component: Layout,
    name: 'ChangePassword',
    meta: {

    },
    children: [
      {
        path: 'updatepassword',
        name: "UpdatePassword",
        component: () => import('@/views/changePassword/ChangePassword.vue'),
        meta: {
          title: '重置密码',
          icon: 'changePassword'
        }
      }
    ]
  },
]

// 404 page must be placed at the end !!!
export const Route_404 = [{ path: '*', redirect: '/404', hidden: true }]




export const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})


const router = createRouter()


// console.log(store, '仓库');
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}



export default router
